package 晚间作业0322;

import java.util.Iterator;
import java.util.LinkedList;

/**
 * 1. 使用LinkedList模拟栈
 */
public class Doc14_01 {
    public static void main(String[] args) {
        MyStack<String> stack = new MyStack<>();
        stack.push("1");
        stack.push("2");
        stack.push("3");
        System.out.println(stack);
        System.out.println("弹出：" + stack.pop());
        System.out.println("弹出：" + stack.pop());
        stack.push("4");
        System.out.println("弹出：" + stack.pop());
        stack.push("5");
        stack.push("6");
        System.out.println(stack);
    }

    public static class MyStack<T> {
        private LinkedList<T> mList;

        public MyStack() {
            mList = new LinkedList<>();
        }

        public void push(T item) {
            mList.push(item);
        }

        public T pop() {
            return mList.pop();
        }

        @Override
        public String toString() {
            return mList.toString();
        }
    }
}
